package com.example.hangzhou.welbeing.tenguoleshenhuo.splash.persenter;

import android.os.Handler;

import com.example.hangzhou.welbeing.tenguoleshenhuo.splash.SplashActivity;
import com.example.hangzhou.welbeing.tenguoleshenhuo.splash.bean.SplashBean;
import com.example.hangzhou.welbeing.tenguoleshenhuo.splash.model.SplashModel;
import com.example.hangzhou.welbeing.tenguoleshenhuo.splash.view.ISplashView;


/**
 * 时间 2018 年 01 月 23.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.tenguo.splash.persenter
 * 工程名 Tenguo
 */
public class SplashPersenter {
    private ISplashView mIsplash;
    private SplashModel miSplashModel;
    private Handler mhandler = new Handler();

    public SplashPersenter(SplashActivity mIsplash) {
        this.mIsplash = mIsplash;
        miSplashModel = new SplashModel();
    }
    /**
     * @desc 请求网络加载数据的逻辑
     * */
    public void requestNetwork(){
        new Thread(){
            @Override
            public void run() {
                super.run();
                SplashBean mSplashBean =  miSplashModel.load();
                if(mSplashBean.getErrorCode() == 200){
                    mhandler.post(new Runnable() {
                        @Override
                        public void run() {
                            mIsplash.toActivity();
                        }
                    });
                }else{
                    mIsplash.toToast(mSplashBean);
                }
            }
        }.start();

    }


}
